// pages/index/login.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show:false,
	  version:app.config.version,
    backUrl: "pages/index/index",
    user:{},//测试数据
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      version:app.globalData.version
    })
    let options_backurl = decodeURIComponent(options.backurl);
    if (app.functions.isEmpty(options_backurl) == false) {
      if (options_backurl != "pages/login/login") {
        that.data.backUrl=options_backurl;
      } else {
        that.data.backUrl="pages/index/index";
      }
    }else {
      that.data.backUrl="pages/index/index";
    }

  },
  onClose(){
    this.setData({
      show:false
    })
  },
  getPhoneNumber(e){
    console.info(e);
    app.functions.setLocalStorage("user",this.data.user);
    app.functions.setLocalStorage("shop",this.data.user);
  },
  bindGetUserInfo(e) {
    wx.vibrateShort();
    let that = this;
    var res = e.detail.userInfo;
    if (!res) {
      return false;
    }
    wx.login({
      success(result) {
        let shareid = app.functions.getLocalStorage("shareUserId");
        let params = {
          code: result.code,
          shareid: shareid ? shareid : '',
          headimgurl: res.avatarUrl,
          nickName: res.nickName,
          gender: res.gender,
          shopImg:"http://img.alicdn.com/bao/uploaded/i2/3015214310/O1CN01NRHQq11hi1dn6AAOx_!!3015214310.jpg",
          quickMarkUrl:"https://image.hnjg.jigon.cn/wx_app_qrcode/20200605135741997.jpg",
          province: "上海市",
          city: "上海市",
          area: "浦东新区",
          address: "杨思地铁口小嘴零食"
        };
        params.id=1;
        that.setData({
          user:params
        })
        console.info(params);
        that.setData({
          show:true
        })
        // app.api.login(params,(res)=>{
        //   if (res.result) {
        //     console.info(res.result.openid);
        //     let param={
        //       openid:res.result.openid
        //     };
        //     app.api.memberGetOne(param,(response)=>{
        //       console.info(response);
        //       app.functions.setLocalStorage("user", response.result);
        //       if(that.data.backUrl.indexOf("pages/index/index")!=-1||that.data.backUrl.indexOf("pages/user/user")!=-1){
        //         wx.switchTab({
        //           url: "/" + that.data.backUrl
        //         });
        //       }else{
        //         wx.redirectTo({
        //           url: "/" + that.data.backUrl
        //         });
        //       }
        //     },(error)=>{
        
        //     })

        //   }
        // },(error)=>{

        // })
      }
    });
  },

  // 退回上一个页面
  toback(){
    wx.vibrateShort();
    wx.switchTab({
      url: "/pages/index/index"
    });
  },
  toMobileLogin(){
    app.functions.setLocalStorage("user",this.data.user);
    app.functions.setLocalStorage("shop",this.data.user);
    wx.navigateTo({
      url: '/pages/mobile_login/mobile_login'
    });
      
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },


})